package com.jcsz.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.jcsz.gulimall.order.config.AlipayTemplate;
import com.jcsz.gulimall.order.entity.OrderEntity;
import com.jcsz.gulimall.order.service.OrderService;
import com.jcsz.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @className: PayWebController
 * @author: 一把Po吉他
 * @date: 2022/11/16 21:07
 * @version: 1.0
 **/
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    @GetMapping(value = "aliPayOrder",produces = "text/html")
    @ResponseBody
    public String aliPayOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {

        PayVo vo = orderService.getPayVoByOrderSn(orderSn);

        String pay = alipayTemplate.pay(vo);
        return pay;
    }
}
